import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ShopConfig } from "../../../resource/ShopConfig";
import { ShopRule } from "../../../rules/ShopRule";
import { EColor } from "../../../../../Message/Public/EColor";
import { EPetLifeStyle } from "../../../../../Message/Public/EPetLifeStyle";
import { Cache } from "../../../cache/Cache";
import { ItemInfo } from "../../../resource/info/ItemInfo";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ObjCreate } from "../../common/ObjCreate";
import { TilePanel } from "../../equipment/TilePanel";
import { PetMingExchangeCellRenderer } from "./PetMingExchangeCellRenderer";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetMingExchangeWindow
    
    export  class PetMingExchangeWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(445, 430);
            this.titleHeight = 47;
            this.title = Language.getString(54763);
            this.typeItemsArr();
            return;
        }

        /* internal  */typeItemsArr(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            this._type0 = ShopConfig.instance.getShopByName(ShopRule.ShopPetMingLifeStyle).items;
            this._type1 = new Array<any>();
            this._type2 = new Array<any>();
            this._type3 = new Array<any>();
            this._type4 = new Array<any>();
            this._type5 = new Array<any>();
            var loc4=0;
            var loc5=this._type0;
            for(loc1 of loc5) 
            {
                loc2 = loc1.itemInfo.item.color;
                loc3 = loc1.itemInfo.item.type;
                if (loc2 == EColor._EColorOrange) 
                {
                    this._type2.push(loc1);
                    continue;
                }
                if (loc2 == EColor._EColorPurple) 
                {
                    this._type3.push(loc1);
                    continue;
                }
                if (loc2 == EColor._EColorBlue && !(loc3 == EPetLifeStyle._EPetLifeStyleExp)) 
                {
                    this._type4.push(loc1);
                    continue;
                }
                if (loc2 == EColor._EColorBlue && loc3 == EPetLifeStyle._EPetLifeStyleExp) 
                {
                    if (!Cache.instance.petMing.isRedEnable) 
                    {
                        this._type5.push(loc1);
                    }
                    continue;
                }
                if (loc2 == EColor._EColorGreen) 
                {
                    this._type5.push(loc1);
                    continue;
                }
                if (loc2 != EColor._EColorRed) 
                {
                    continue;
                }
                if (!Cache.instance.petMing.isRedEnable) 
                {
                    continue;
                }
                this._type1.push(loc1);
            }
            return;
        }

        public updateBrokenSoul(arg1: int): void
        {
            this._suipianTxt.text = arg1.toString();
            this.tabBarChangeHandler(null, this.curIndex);
            return;
        }

        /* internal  */isPetMing(arg1: ItemInfo): Boolean
        {
            return arg1 && arg1.item && arg1.item.category == ECategory._ECategoryPetLifeStyle;
        }

        public tabBarChangeHandler(arg1: MuiEvent=null, arg2: int=0): void
        {
            if (arg1) 
            {
                arg2 = this._tabBar.selectedIndex;
            }
            this.curIndex = arg2;
            this._itemsPanel.dataProvider = new DataProvider(this["_type" + this.curIndex]);
            if (this._itemsPanel.verticalScrollBar) 
            {
                this._itemsPanel.verticalScrollBar.scrollPosition = 0;
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tabBar = new GTabBar();
            this._tabBar.buttonWidth = 65;
            this._tabBar.horizontalGap = 2;
            this._tabBar.buttonFilters = [FilterConst.glowFilter];
            var loc1=new Array<any>();
            loc1.push({"label": Language.getString(54924), "name":"1", "id": 0});
            loc1.push({"label": Language.getString(54941), "name":"6", "id": 5});
            loc1.push({"label": Language.getString(54925), "name":"2", "id": 1});
            loc1.push({"label": Language.getString(54926), "name":"3", "id": 2});
            loc1.push({"label": Language.getString(54927), "name":"4", "id": 3});
            loc1.push({"label": Language.getString(54928), "name":"5", "id": 4});
            this._tabBar.dataProvider = loc1;
            this._tabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.tabBarChangeHandler);
            this._tabBar.selectedIndex = this.curIndex;
            ObjCreate.setObjAttri(this._tabBar, 20, 33, -1, -1, this);
            ObjCreate.createBg(17, 58, 411, 319, this);
            this._itemsPanel = new TilePanel();
            this._itemsPanel.setSize(395, 315);
            this._itemsPanel.columnWidth = 187;
            this._itemsPanel.rowHeight = 106;
            this._itemsPanel.setStyle("cellRenderer", PetMingExchangeCellRenderer);
            this._itemsPanel.move(30, 63);
            this.addChild(this._itemsPanel);
            ObjCreate.createBg(17, 378, 411, 41, this);
            ObjCreate.createBitmap(ImagesConst.Fire, 160, 384, this);
            ObjCreate.createTextField(Language.getString(54930), 181, 390, 100, 18, this, GlobalStyle.textFormat6);
            this._suipianTxt = ObjCreate.createGTextField("", 262, 390, 100, 20, this, GlobalStyle.textFormatOrange);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.tabBarChangeHandler(null, this.curIndex);
            this.updateBrokenSoul(Cache.instance.role.money.brokenSoul);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._itemsPanel.dataProvider = new DataProvider([]);
            return;
        }

        /* internal */ /* var */_suipianTxt: GTextFiled;

        /* internal */ /* var */_itemsPanel: TilePanel;

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_type0: Array<any>;

        /* internal */ /* var */_type1: Array<any>;

        /* internal */ /* var */_type2: Array<any>;

        /* internal */ /* var */_type3: Array<any>;

        /* internal */ /* var */_type4: Array<any>;

        /* internal */ /* var */_type5: Array<any>;

        /* internal */ /* var */curIndex: int=0;
    }
